<?php
/**
 * @author CptSoap
 * @email 694652150@qq.com
 * @date 2021/9/27
 * 日志实时打印到文件中
 */

namespace app\admin\utils;

class ontimeLog
{
    static function mylog($data, $file, $method)
    {
//        $myFile = "/Users/ninglonghui/PhpstormProjects/php-mall/log.txt";
        $myFile = ROOT_PATH . DS . 'log.txt';
        $fh = fopen($myFile, 'a') or die("can't open file");

        fwrite($fh, date('Y-m-d h:i:s', time()));
        fwrite($fh, ' [' . basename($file) . ']-');
        fwrite($fh, '[' . $method . '] : ');

        fwrite($fh, json_encode($data));
        fwrite($fh, PHP_EOL);
        fclose($fh);
    }
}
